<?php

namespace App\Admin\Controllers;

use App\Library\Models\AdminSourceMaterialModel;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;

class SourceMaterialController extends AdminController
{
    protected $title = '素材';

    public function paging(Content $content): Content
    {
        return $content->title($this->title())->description($this->description['index'] ?? trans('admin.list'))
            ->body(view('sourceMaterial.paging', [
                'newAuth' => aesEncrypt(encodeId(Admin::user()->user_id))
            ]));
    }

    public function detail(Content $content): Content
    {
        $model = AdminSourceMaterialModel::query()
            ->select('source_material.*', 'shop_user.user_mobile')
            ->leftJoin('shop_user', 'shop_user.user_id', 'source_material.user_id')
            ->orderByDesc('source_material.created_at')
            ->where('source_material.serial_number', request()->segment(4))
            ->first();

        return $content->title($this->title())->description($this->description['index'] ?? trans('admin.list'))
            ->body(view('sourceMaterial.detail', [
                'newAuth' => aesEncrypt(encodeId(Admin::user()->user_id)),
                'data' => $model
            ]));
    }
}
